/**
 * FileName: EmployeeService
 * Author: Administrator
 * Date: 2018/11/19 18:33
 * Description:
 */
package com.cym.service;

import com.cym.bean.Employee;
import com.cym.bean.EmployeeExample;
import com.cym.dao.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    
    public List<Employee> find() {
       return employeeMapper.selectByExampleWithDept(null);
    }

    public void addEmployeeInfo(Employee employee) {
       employeeMapper.insertSelective(employee);
    }

    /**
     * 检验用户名是否可用
     * 如果返回true（数据库里没有同名的人），表示 用户可用，false:表示用户不可用。
     * @param empName
     * @return
     */
    public Boolean checkUser(String empName) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count = employeeMapper.countByExample(example);
        return count == 0;
    }

    public Employee findEmpNameById(Integer id) {
        Employee employee = employeeMapper.selectByPrimaryKey(id);
        return employee;
    }

    public void updateEmployee(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

    public void deleteEmployee(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

    public void deleteBath(List<Integer> idList) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        criteria.andEmpIdIn(idList);
        employeeMapper.deleteByExample(example);
    }
}
